﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.TcCommands.TcReplace.CApReplaceWithValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.TcCommands.TcReplace;

internal class CApReplaceWithValidator : CApReplaceWhatValidator
{
  internal CApReplaceWithValidator(CUiReplaceDialog replaceDialog)
    : base(replaceDialog)
  {
  }

  public override bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    bool flag = false;
    errorMessage = (string) null;
    using (new TxCallMessages.Collector((object) "CApReplaceWithValidator.IsValidObject"))
    {
      if (obj == null)
        errorMessage = StringTable.REPLACE_PROTOTYPE_INVALID_OBJECT_ERROR;
      else if (obj is ITxComponent)
      {
        flag = CApReplaceWhatValidator.IsResource(obj) || CApReplaceWhatValidator.IsCompoundEquipment(obj);
        if (flag)
        {
          flag = this.IsReplacementAllowed(this._replaceDialog.grInstResources.Objects, obj);
          if (!flag)
          {
            errorMessage = string.Join("\n", TxCallMessages.GetMessages());
            if (string.IsNullOrEmpty(errorMessage))
              errorMessage = StringTable.REPLACE_PROTOTYPE_INVALID_OBJECT_ERROR;
          }
        }
        else
          errorMessage = StringTable.REPLACE_PROTOTYPE_NOT_A_RESOURCE_ERROR;
      }
      else
        errorMessage = StringTable.REPLACE_PROTOTYPE_NOT_A_COMPONENT_ERROR;
    }
    return flag;
  }
}
